<!DOCTYPE html >
<html xmlns:th="http://www.thymeleaf.org" lang="en">
<head>
    <title>任务日志</title>
    <script th:replace="common/head::static"></script>
</head>
<body>

<div class="layui-fluid">
    <div class="layui-card">
        <fieldset class="layui-elem-field">
            <legend>条件搜索</legend>
            <form class="layui-form layui-card-header" id="sysJobLogSearchForm">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label">任务名</label>
                        <div class="layui-input-inline">
                            <input type="text" name="jobName" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label">日期范围</label>
                        <div class="layui-input-inline">
                            <input type="text" class="layui-input" id="createdDateId" placeholder=" - ">
                            <!-- 设置日期 -->
                            <input type="text" name="createdDateStart" id="createdDateStart" th:hidden="true">
                            <input type="text" name="createdDateEnd" id="createdDateEnd" th:hidden="true">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <!-- type="button" 阻止默认行为提交form表单 -->
                        <button type="button" class="layui-btn" id="sysJobLogSearchBtn">
                            <i class="layui-icon layui-icon-search"></i>查询
                        </button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </fieldset>

        <div class="layui-card-body">
            <table class="layui-hide" id="sysJobLogTable" lay-filter="sysJobLogTableFilter"></table>
            <script type="text/html" id="toolBars">
                <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">
                    <i class="layui-icon layui-icon-delete"></i>删除</a>
            </script>
        </div>
    </div>
</div>

<script th:src="@{/common/js/common.js}"></script>
<script th:inline="javascript">
    layui.use(['table', 'form', 'laydate'], function () {
        const table = layui.table
            , $ = layui.jquery
            , laydate = layui.laydate
            , form = layui.form;
        form.render();

        //执行一个laydate实例
        laydate.render({
            elem: '#createdDateId'//指定元素
            , range: true
            , type: 'date'
            , min: '1900-1-1'
            , max: '2099-12-31'
            , lang: 'cn'
            , theme: 'default'
            , calendar: true
            , format: 'yyyy-MM-dd'
            , done: function(value, date, endDate){
                // console.log(value); //得到日期生成的值，如：2017-08-18
                // console.log(date); //得到日期时间对象：{year: 2017, month: 8, date: 18, hours: 0, minutes: 0, seconds: 0}
                // console.log(endDate); //得结束的日期时间对象，开启范围选择（range: true）才会返回。对象成员同上。
                var dateArr = value.split(' - ');
                $('#createdDateStart').val(dateArr[0]);
                $('#createdDateEnd').val(dateArr[1]);
            }
        });

        const cols = [[
            {field: 'checkBox', checkbox: true, fixed: true}
            , {field: 'jobName', title: '任务名', align: 'center'}
            // , {field: 'jobGroup', title: '任务组名', align: 'center'}
            // , {field: 'invokeTarget', title: '调用目标字符串', align: 'center'}
            , {field: 'jobMessage', title: '日志信息', align: 'center'}
            // , {
            //     field: 'status', title: '执行状态', align: 'center', templet: function (d) {
            //         return d.status === '0' ? '正常' : '失败';
            //     }
            // }
            , {field: 'exceptionInfo', title: '异常信息', align: 'center'}
            , {field: 'startTime', title: '开始时间', align: 'center'}
            , {field: 'endTime', title: '结束时间', align: 'center'}
            // , {field: 'createdBy', title: '创建人', align: 'center'}
            // , {field: 'createdDate', title: '创建时间', align: 'center'}
            , {field: 'op', title: '操作', align: 'center', width: '8%', toolbar: '#toolBars'} //这里的toolbar值是模板元素的选择器
        ]];

        const layuiTable = Common.getLayuiTable(table, '#sysJobLogTable', ctx + '/sysJobLog/findPage', cols);

        $('#sysJobLogSearchBtn').on('click', function () {
            Common.reloadTable($('#sysJobLogSearchForm'), layuiTable);
        });

        //监听工具条 https://www.layui.com/doc/modules/table.html#toolbar
        table.on('tool(sysJobLogTableFilter)', function (obj) { //注：tool 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
            var data = obj.data; //获得当前行数据
            var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
            var tr = obj.tr; //获得当前行 tr 的 DOM 对象（如果有的话）
            if (layEvent === 'del') { //删除
                layer.confirm('真的删除行么', function (index) {
                    Common.ajaxDelete('/sysJobLog/delete/' + data.id, {}, function (res) {
                        layer.close(index);
                        layer.msg(res.message, {icon: 6}, function () {
                            $('#sysJobLogSearchBtn').click();
                        });
                    });
                });
            }
        });

    });

</script>
</body>
</html>